<template>
	<mdp-lr-box :lspan="6" :expand="false" :disabled="xmMenu?.menuId || parentTask?.id || deriveId" @expand="onExpand">
		<template #left>
			<xm-phase :isTpl="isTpl" subOpType="mng" :xm-product="xmProduct" :xm-collect="xmCollect" :sel-project="selProject"  @check-change="onPhaseRowClick" @project-select="onProjectSelect" @project-clear="onProjectClear"/>
		</template>
		<xm-task-mng ref="xmTaskMngRef" :deriveId="deriveId" :adaptiveDisabled="adaptiveDisabled" :isTpl="isTpl" :queryScope="queryScope||'planTask'" :key="selProject?.id?selProject?.id:project?.id"  :subOpType="subOpType" :xm-menu="xmMenu" :multiple="multiple" :xm-product="xmProduct" :xm-collect="xmCollect" :xmIteration="xmIteration" :sel-project="selProject?.id?selProject:project" :params="myParams" :parent-task="parentTask?.id?parentTask:parent" :kpi-id="kpiId" @select="(v)=>$emit('select',v)"/>
	</mdp-lr-box>
</template>

<script>

import util from '@/components/mdp-ui/js/util';//全局公共库

import { mapState } from 'pinia'
import { useUserStore } from '@/store/modules/user'

 
// 在 Vue 3 中，可以使用 defineAsyncComponent 方法来创建异步组件
import { defineAsyncComponent } from 'vue';
  
 // 创建一个异步组件，它会从一个外部API动态导入组件
 const XmTaskMng = defineAsyncComponent(() =>
	 import('../xmTask/XmTaskMng.vue') // 假设LazyComponent.vue是你想要懒加载的组件
 );// 创建一个异步组件，它会从一个外部API动态导入组件 

export default {
	name:'XmTaskBox',
	components: {
		XmTaskMng
	},
			props:['xmProduct','xmIteration','selProject','multiple','xmMenu','subOpType',
			"queryScope","deriveId","isTpl","adaptiveDisabled",
    "params","xmCollect","kpiId",
    "parentTask"],
	computed: {
			...mapState(useUserStore,[
				'userInfo','roles'
			]),

			myParams(){
				if(this.params){
					if(this.parent?.id){ 
						return  {...this.params,parentTaskid:this.parent.id}
					}else{
						return this.params
					}
				}else{
					if(this.parent?.id){
						return {parentTaskid:this.parent.id} 
					}else{
						return null
					}
				}  
			},
	},
	watch: {

		},
	data() {
		return {
			parent:null,
				hadInit: false, 
				project:null,
		}//end return
	},//end data
	methods: {
		searchTableDatas(){
			this.$refs['xmTaskMngRef'].searchTableDatas();
		},
		onExpand(expand){
			if(expand==true){
				this.hadInit=true
			}
		},
 
		 onPhaseRowClick(task,checked){
			if(checked==true){
				this.parent=task
			}else{
				this.parent=null
			}
			 
		 },
		 onProjectSelect(project){
			this.project=project
			this.parent=null
			this.$emit('project-select',project)
		 },
		 onProjectClear(){
			this.project=null
			this.parent=null
			
			this.$emit('project-clear')
		 }
	},//end method
	mounted() {
		this.parent=this.parentTask
		this.project=this.selProject

	}//end mounted
}

</script>

<style lang="less" scoped />
